package sdk.pay.model;

import android.content.Context;
import android.content.Intent;

import java.net.URISyntaxException;

import sdk.pay.basepay.UnifiedPay;
import sdk.pay.utils.PayExceptionUtil;
import sdk.pay.utils.PayLogUtil;

/**
 * Created by Administrator on 2017/5/22.
 */

public class WapPay extends UnifiedPay {
    private boolean mIsPilotRun;

    public WapPay(String content, boolean isPilotRun, Context context) {
        super(content, context);
        mIsPilotRun = isPilotRun;
    }

    public void setIsPilotRun(boolean isPilotRun) {
        mIsPilotRun = isPilotRun;
    }

    @Override
    public void pay(CallBack callBack) {
        mCallBack = callBack;
        wapPay();
    }

    private void wapPay() {
        Intent intent;
        PayLogUtil.logBase("wapPay url = " + getContent());
        if (!mIsPilotRun) {
            try {
                intent = Intent.parseUri(getContent(), Intent.URI_INTENT_SCHEME);
                intent.addCategory(Intent.CATEGORY_BROWSABLE);
                intent.setComponent(null);
                intent.setSelector(null);
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                mContext.startActivity(intent);
            } catch (URISyntaxException e) {
                e.printStackTrace();
                PayExceptionUtil.getInstance().saveExceptionFile("wapPay exception message = " + e.getMessage());
            } finally {
                prepareLeave();
            }
        }
        PayLogUtil.logSecond("wapPay end mIsPilotRun = " + mIsPilotRun);
    }
}
